export function deepTreeTwo(list) {
  // 最终结果集合
  const result = [];
  // 映射对象
  const map = {};

  list.forEach((item) => {
    map[item.id] = { ...item, children: [] };

    const newItem = map[item.id];

    if (item.parentId === null) {
      result.push(newItem);
    } else {
      if (Object.prototype.hasOwnProperty.call(map, item.parentId)) {
        map[item.parentId].children?.push(newItem);
      } else {
        result.push(newItem);
      }
    }
  });

  return result;
}

const result = deepTreeTwo([
  {
    id: 3,
    createTime: "2023-04-26 22:46:59",
    updateTime: "2023-04-26 22:47:11",
    parentId: 2,
    name: "菜单列表",
    router: "/sys/menu",
    perms: null,
    type: 1,
    icon: "icon-menu",
    orderNum: 1,
    viewPath: "cool/modules/base/views/menu.vue",
    keepAlive: 1,
    isShow: 1,
    parentName: "系统管理",
  },
]);
console.log("result", result);
